<!doctype html><html lang=en-us dir=ltr><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><meta name=description content="Python 机器学习库 👽 # Plotly # 与matplotlib 都是绘图工具，不过效果炫一些，我也没画过，所以只放链接，不放实例了 Plotly Python Library : https://plot.ly/python/
matplotlib # import matplotlib.pyplot as plt 参数等太多，链接最可靠 # pyplot参数
还是粘一些常用的： marker 属性（下面写在分号里呦） o . v ^ < > 1 2 3 4 8 s p * h H + x D d | _ 之类
画出一些“花儿”
绘图 # plt.plot(x, y) # 在y之后可添加参数，例如常用的label = ‘IamLabel’之类 # 线的样式、颜色 ：b: blue g: green r: red c: cyan m: magenta y: yellow k: black w: white '-' : solid , '--' : dashed, '-."><meta name=theme-color content="#FFFFFF"><meta name=color-scheme content="light dark"><meta property="og:title" content="机器学习库"><meta property="og:description" content="Python 机器学习库 👽 # Plotly # 与matplotlib 都是绘图工具，不过效果炫一些，我也没画过，所以只放链接，不放实例了 Plotly Python Library : https://plot.ly/python/
matplotlib # import matplotlib.pyplot as plt 参数等太多，链接最可靠 # pyplot参数
还是粘一些常用的： marker 属性（下面写在分号里呦） o . v ^ < > 1 2 3 4 8 s p * h H + x D d | _ 之类
画出一些“花儿”
绘图 # plt.plot(x, y) # 在y之后可添加参数，例如常用的label = ‘IamLabel’之类 # 线的样式、颜色 ：b: blue g: green r: red c: cyan m: magenta y: yellow k: black w: white '-' : solid , '--' : dashed, '-."><meta property="og:type" content="article"><meta property="og:url" content="http://example.org/docs/programmer/ml/noteofmachinelearning/"><meta property="article:section" content="docs"><title>机器学习库 | Ian's Blog</title>
<link rel=manifest href=/manifest.json><link rel=icon href=/favicon.png type=image/x-icon><link rel=stylesheet href=/book.min.c58292d36b18b675680ab9baea2029204537b839ea72f258746ec0f32ce8d6c8.css integrity="sha256-xYKS02sYtnVoCrm66iApIEU3uDnqcvJYdG7A8yzo1sg=" crossorigin=anonymous><script defer src=/flexsearch.min.js></script><script defer src=/en.search.min.2d8d2bb9754cea7562c9f4c6dd439b23aa4670e648a288ebbc817f1f4eaa725f.js integrity="sha256-LY0ruXVM6nViyfTG3UObI6pGcOZIoojrvIF/H06qcl8=" crossorigin=anonymous></script></head><body dir=ltr><input type=checkbox class="hidden toggle" id=menu-control>
<input type=checkbox class="hidden toggle" id=toc-control><main class="container flex"><aside class=book-menu><div class=book-menu-content><nav><h2 class=book-brand><a class="flex align-center" href=/><span>Ian's Blog</span></a></h2><div class=book-search><input type=text id=book-search-input placeholder=Search aria-label=Search maxlength=64 data-hotkeys=s/><div class="book-search-spinner hidden"></div><ul id=book-search-results></ul></div><ul><li class=book-section-flat><a href=/docs/programmer/>程序员笔记</a><ul><li><input type=checkbox id=section-8658298e10b544e890095f646916165a class=toggle>
<label for=section-8658298e10b544e890095f646916165a class="flex justify-between"><a role=button>云原生</a></label><ul><li><input type=checkbox id=section-62d608ed890b3abc76dae78ccfcab912 class=toggle>
<label for=section-62d608ed890b3abc76dae78ccfcab912 class="flex justify-between"><a role=button>k8s</a></label><ul><li><a href=/docs/programmer/cloudnative/k8s/elk%E5%9C%A8k8s%E4%B8%8A%E7%9A%84%E9%83%A8%E7%BD%B2%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B/>elk在k8s上的部署使用示例</a></li><li><a href=/docs/programmer/cloudnative/k8s/k8s-%E9%85%8D%E5%A5%97%E8%AF%B4%E6%98%8E/>k8s 配套说明</a></li><li><a href=/docs/programmer/cloudnative/k8s/k8s-%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/>k8s技术分享</a></li><li><a href=/docs/programmer/cloudnative/k8s/k8s%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%A7%A3%E6%9E%90/>k8s学习-常用命令和配置文件</a></li><li><a href=/docs/programmer/cloudnative/k8s/argo-workflow%E6%80%A7%E8%83%BD%E6%B5%8B%E8%AF%95%E5%92%8C%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF%E5%88%86%E6%9E%90/>Argo Workflow性能测试和使用场景分析</a></li><li><a href=/docs/programmer/cloudnative/k8s/argo-%E4%BD%BF%E7%94%A8%E8%AE%B0%E5%BD%95/>Argo 使用记录</a></li></ul></li><li><input type=checkbox id=section-b828bf3d116bc282da9db25a06bf908e class=toggle>
<label for=section-b828bf3d116bc282da9db25a06bf908e class="flex justify-between"><a role=button>中间件</a></label><ul><li><a href=/docs/programmer/cloudnative/middleware/kafka-%E5%AE%89%E8%A3%85%E5%92%8C%E4%BD%BF%E7%94%A8/>Kafka 安装和使用</a></li></ul></li><li><a href=/docs/programmer/cloudnative/noteofdocker/>Docker</a></li><li><a href=/docs/programmer/cloudnative/tipsofweb/>Nginx高可用</a></li><li><a href=/docs/programmer/cloudnative/notesdjango/>Django的建站的(｡･･)ﾉﾞ</a></li><li><a href=/docs/programmer/cloudnative/sonar-%E4%BB%A3%E7%A0%81%E9%9D%99%E6%80%81%E6%A3%80%E6%9F%A5/>Sonar 代码静态检查</a></li></ul></li><li><input type=checkbox id=section-de7bfad1d124522974cdf8addfbb23f2 class=toggle>
<label for=section-de7bfad1d124522974cdf8addfbb23f2 class="flex justify-between"><a role=button>Net</a></label><ul><li><a href=/docs/programmer/net/uwsgi-%E5%A4%84%E7%90%86%E8%AE%B0%E5%BD%95/>uwsgi 处理记录</a></li><li><a href=/docs/programmer/net/tipsofgrpc/>gRpc使用小记</a></li><li><a href=/docs/programmer/net/net/>Epoll实现</a></li><li><a href=/docs/programmer/net/nginx%E5%AE%9E%E7%94%A8%E9%85%8D%E7%BD%AE/>Nginx实用配置</a></li></ul></li><li><input type=checkbox id=section-bf4e0d6f0b81f7b3ec08ed1fc66b874d class=toggle>
<label for=section-bf4e0d6f0b81f7b3ec08ed1fc66b874d class="flex justify-between"><a role=button>编程语言</a></label><ul><li><input type=checkbox id=section-771df6c720301e69f1715f7fc174ac3d class=toggle>
<label for=section-771df6c720301e69f1715f7fc174ac3d class="flex justify-between"><a role=button>Python</a></label><ul><li><a href=/docs/programmer/langs/python/pypi/>PyPi使用说明</a></li><li><a href=/docs/programmer/langs/python/paramiko-%E4%BD%BF%E7%94%A8-sshsftp/>Paramiko 使用 Ssh&amp;sftp</a></li><li><a href=/docs/programmer/langs/python/pytest/>Pytest</a></li><li><a href=/docs/programmer/langs/python/notespython/>笔记</a></li></ul></li><li><input type=checkbox id=section-9f8ac8f06e138c7ac13ff61f23b4d497 class=toggle>
<label for=section-9f8ac8f06e138c7ac13ff61f23b4d497 class="flex justify-between"><a role=button>Golang</a></label><ul><li><a href=/docs/programmer/langs/golang/noteofgoexp/>Golang进阶笔记</a></li><li><a href=/docs/programmer/langs/golang/noteofgolang/>Golang笔记</a></li></ul></li><li><a href=/docs/programmer/langs/cmake/>CMake 使用Tips</a></li><li><a href=/docs/programmer/langs/tipsofdebugers/>tips Of Debuggers</a></li><li><a href=/docs/programmer/langs/tipsofmarkdown/>Markdown</a></li><li><a href=/docs/programmer/langs/markdown/>Markdown</a></li><li><a href=/docs/programmer/langs/java/notesjava/>愉快的Java(happy to learn the fuck java)</a></li><li><a href=/docs/programmer/langs/noteoffmtdata/>数据格式笔记</a></li></ul></li><li><input type=checkbox id=section-883e27361d38e16afb68faff3435ac0b class=toggle checked>
<label for=section-883e27361d38e16afb68faff3435ac0b class="flex justify-between"><a role=button>机器学习</a></label><ul><li><a href=/docs/programmer/ml/tensorflow/>Tensorflow</a></li><li><a href=/docs/programmer/ml/opencv/>OpenCV</a></li><li><a href=/docs/programmer/ml/paddle/>Paddle</a></li><li><a href=/docs/programmer/ml/yolo/>Demo Test项目中的一些东西</a></li><li><a href=/docs/programmer/ml/noteofmachinelearning/ class=active>机器学习库</a></li></ul></li><li><input type=checkbox id=section-7e5360c5e7954906b897ed79085884b6 class=toggle>
<label for=section-7e5360c5e7954906b897ed79085884b6 class="flex justify-between"><a href=/docs/programmer/gui/>图形用户界面-GUI</a></label><ul><li><a href=/docs/programmer/gui/pyinstaller/>python打包</a></li><li><a href=/docs/programmer/gui/qt/>Qt/PySide</a></li><li><a href=/docs/programmer/gui/noteofvn_py/>Vn.Py学习笔记（Python交易平台框架）</a></li><li><a href=/docs/programmer/gui/notespython/>图形化界面 （Python Gui）</a></li></ul></li><li><input type=checkbox id=section-ddcbe632dc99a9fb372422dada8ee641 class=toggle>
<label for=section-ddcbe632dc99a9fb372422dada8ee641 class="flex justify-between"><a role=button>OS操作系统问题处理</a></label><ul><li><a href=/docs/programmer/os/install_some/>安装问题</a></li><li><a href=/docs/programmer/os/noteoflinux/>Linux</a></li><li><a href=/docs/programmer/os/android/>Android</a></li><li><a href=/docs/programmer/os/freebsd/>Freebsd</a></li><li><a href=/docs/programmer/os/npm/>Npm</a></li><li><a href=/docs/programmer/os/tipsofproblems/>解决问题</a></li></ul></li><li><input type=checkbox id=section-4446dd07527142b855f26d7cc8f0e617 class=toggle>
<label for=section-4446dd07527142b855f26d7cc8f0e617 class="flex justify-between"><a role=button>Database</a></label><ul><li><a href=/docs/programmer/database/dgraph/>Dgraph使用小记</a></li><li><a href=/docs/programmer/database/noteofdbdata/>db数据库</a></li><li><a href=/docs/programmer/database/mongodb/>Mongodb</a></li><li><a href=/docs/programmer/database/tip_dgraph/>Dgraph</a></li></ul></li><li><input type=checkbox id=section-d5f99046a51e5e750b61f2e037945fcc class=toggle>
<label for=section-d5f99046a51e5e750b61f2e037945fcc class="flex justify-between"><a role=button>基础工具和配置</a></label><ul><li><a href=/docs/programmer/basetc/for_china/>各个软件换源</a></li><li><a href=/docs/programmer/basetc/tipsofvim/>tip Of vim</a></li><li><a href=/docs/programmer/basetc/editer/>编辑器使用</a></li><li><a href=/docs/programmer/basetc/bash/>Bash</a></li><li><a href=/docs/programmer/basetc/gitbook/>Gitbook</a></li><li><a href=/docs/programmer/basetc/vim/>Vim</a></li></ul></li><li><input type=checkbox id=section-d325c59fc6513e1b1e05a60b192d4973 class=toggle>
<label for=section-d325c59fc6513e1b1e05a60b192d4973 class="flex justify-between"><a href=/docs/programmer/hardware/>硬件</a></label><ul><li><a href=/docs/programmer/hardware/raspberrypi/>Raspberry Pi</a></li><li><a href=/docs/programmer/hardware/screen/>Screen</a></li></ul></li></ul></li><li class=book-section-flat><span>建模和游戏</span><ul><li><a href=/docs/3dgame/blender/>Blender</a></li><li><a href=/docs/3dgame/noteofue4/>UE4 笔记</a></li></ul></li><li class=book-section-flat><a href=/docs/example/>Hugo特殊Markdown语法说明</a><ul><li><a href=/docs/example/table-of-contents/>Table of Contents</a><ul><li><a href=/docs/example/table-of-contents/with-toc/>With ToC</a></li><li><a href=/docs/example/table-of-contents/without-toc/>Without ToC</a></li></ul></li><li><a href=/docs/example/shortcodes/buttons/>Buttons</a></li><li><a href=/docs/example/shortcodes/columns/>Columns</a></li><li><a href=/docs/example/shortcodes/details/>Details</a></li><li><a href=/docs/example/shortcodes/expand/>Expand</a></li><li><a href=/docs/example/shortcodes/hints/>Hints</a></li><li><a href=/docs/example/shortcodes/tabs/>Tabs</a></li></ul></li></ul><ul><li><a href=/posts/>Blog</a></li></ul></nav><script>(function(){var e=document.querySelector("aside .book-menu-content");addEventListener("beforeunload",function(){localStorage.setItem("menu.scrollTop",e.scrollTop)}),e.scrollTop=localStorage.getItem("menu.scrollTop")})()</script></div></aside><div class=book-page><header class=book-header><div class="flex align-center justify-between"><label for=menu-control><img src=/svg/menu.svg class=book-icon alt=Menu>
</label><strong>机器学习库</strong>
<label for=toc-control><img src=/svg/toc.svg class=book-icon alt="Table of Contents"></label></div><aside class="hidden clearfix"><nav id=TableOfContents><ul><li><ul><li><a href=#plotly>Plotly</a></li></ul></li><li><a href=#matplotlib>matplotlib</a><ul><li><a href=#参数等太多链接最可靠>参数等太多，链接最可靠</a></li><li><a href=#绘图>绘图</a></li><li><a href=#绘制图表>绘制图表</a></li><li><a href=#一表多图>一表多图</a></li><li><a href=#标注点>标注点</a></li><li><a href=#坐标标签显示方案>坐标标签显示方案</a></li><li><a href=#来画一个动态图吧感觉没啥作用所以就小标题了>来画一个动态图吧（感觉没啥作用所以就小标题了）</a></li></ul></li><li><a href=#pandas>pandas</a><ul><li><a href=#dataframe>DataFrame</a></li></ul></li><li><a href=#numpy>numpy</a><ul><li><a href=#random>random</a></li></ul></li><li><a href=#scikit-learn>scikit-learn</a></li><li><a href=#opencv>OpenCV</a><ul><li><a href=#insatll>Insatll</a></li></ul></li><li><a href=#pil>PIL</a></li></ul><ul><li><a href=#问题>问题</a><ul><li><a href=#sslerror-https>SSLError HTTPS</a></li></ul></li><li><a href=#selenium>Selenium</a><ul><li></li></ul></li><li><a href=#tensorflow>TensorFlow</a><ul><li></li></ul></li><li><a href=#tensorflow-笔记>Tensorflow 笔记</a><ul><li><a href=#1-1>1</a></li></ul></li><li><a href=#tensorflow-笔记-1>Tensorflow 笔记</a><ul><li><a href=#1-2>1</a></li></ul></li></ul></nav></aside></header><article class=markdown><h1 id=python-机器学习库->Python 机器学习库 👽
<a class=anchor href=#python-%e6%9c%ba%e5%99%a8%e5%ad%a6%e4%b9%a0%e5%ba%93->#</a></h1><h3 id=plotly>Plotly
<a class=anchor href=#plotly>#</a></h3><p>与matplotlib 都是绘图工具，不过效果炫一些，我也没画过，所以只放链接，不放实例了
<a href=https://plot.ly/python/>Plotly Python Library</a> : <a href=https://plot.ly/python/>https://plot.ly/python/</a></p><h2 id=matplotlib>matplotlib
<a class=anchor href=#matplotlib>#</a></h2><pre><code>import matplotlib.pyplot as plt
</code></pre><h3 id=参数等太多链接最可靠>参数等太多，链接最可靠
<a class=anchor href=#%e5%8f%82%e6%95%b0%e7%ad%89%e5%a4%aa%e5%a4%9a%e9%93%be%e6%8e%a5%e6%9c%80%e5%8f%af%e9%9d%a0>#</a></h3><p><a href=https://github.com/wizardforcel/matplotlib-user-guide-zh/blob/master/3.1.md>pyplot参数</a></p><p>还是粘一些常用的：
marker 属性（下面写在分号里呦）
o . v ^ &lt; > 1 2 3 4 8 s p * h H + x D d | _ 之类</p><p><a href=http://blog.csdn.net/pipisorry/article/details/40005163>画出一些“花儿”</a></p><h3 id=绘图>绘图
<a class=anchor href=#%e7%bb%98%e5%9b%be>#</a></h3><pre><code>plt.plot(x, y)
# 在y之后可添加参数，例如常用的label = ‘IamLabel’之类
# 线的样式、颜色 ：b: blue  g: green    r: red  c: cyan m: magenta
y: yellow   k: black    w: white
'-' : solid , '--' : dashed, '-.' : dashdot ':' : dotted    '   '', ' '   ': None
# 粗细 lw=3 更改数字
# 数值折点显示样式 marker = ‘o’   

plot.show()
</code></pre><h3 id=绘制图表>绘制图表
<a class=anchor href=#%e7%bb%98%e5%88%b6%e5%9b%be%e8%a1%a8>#</a></h3><h4 id=1>1
<a class=anchor href=#1>#</a></h4><pre><code>plt.figure(1)
绘图
plt.figure(2)
绘图
</code></pre><h4 id=2未测试>2（未测试）
<a class=anchor href=#2%e6%9c%aa%e6%b5%8b%e8%af%95>#</a></h4><pre><code>plt.figure(1)   # 创建图表1
plt.figure(2)   # 创建图表2
hi1 = plt.subplot(211)  # 在图表2中创建子图1
hi2 = plt.subplot(212)  # 在图表2中创建子图2
</code></pre><h3 id=一表多图>一表多图
<a class=anchor href=#%e4%b8%80%e8%a1%a8%e5%a4%9a%e5%9b%be>#</a></h3><pre><code>pCapital = plt.subplot(4, 1, 1)
    pCapital.set_ylabel(&quot;capital&quot;)
    pCapital.plot(d['capitalList'], color='r', lw=0.8)
plt.show()
</code></pre><h3 id=标注点>标注点
<a class=anchor href=#%e6%a0%87%e6%b3%a8%e7%82%b9>#</a></h3><h4 id=eg1>eg1
<a class=anchor href=#eg1>#</a></h4><pre><code>for w, m in enumerate(self.lowestPrice):
        if w % 120*10 == 0:
            plt.plot([w, w], [m, self.highestPrice[w]], linestyle = '--')
        #plt.scatter(self.dealPoints,color = 'c')
for i in self.dealPoints:           
    plt.scatter([i[0]], [i[1]], color = 'c')    
    for ii in self.ydealPoints:
    plt.scatter([ii[0]], [ii[1]], color = 'm')
    
plt.title('Tick &amp; TradePoint')
plt.legend()
plt.show()
</code></pre><p>plt.legend()
# show() 之前不加这句是不会显示出标注的呦</p><h4 id=eg2还不晓得咋回事儿>eg2(还不晓得咋回事儿)
<a class=anchor href=#eg2%e8%bf%98%e4%b8%8d%e6%99%93%e5%be%97%e5%92%8b%e5%9b%9e%e4%ba%8b%e5%84%bf>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=display:flex><span><span style=color:#f92672>import</span> numpy <span style=color:#66d9ef>as</span> np
</span></span><span style=display:flex><span>t <span style=color:#f92672>=</span> <span style=color:#ae81ff>2</span> <span style=color:#f92672>*</span> np<span style=color:#f92672>.</span>pi <span style=color:#f92672>/</span> <span style=color:#ae81ff>3</span>
</span></span><span style=display:flex><span>plt<span style=color:#f92672>.</span>plot([t, t], [<span style=color:#ae81ff>0</span>, np<span style=color:#f92672>.</span>cos(t)], color<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;blue&#39;</span>, linewidth<span style=color:#f92672>=</span><span style=color:#ae81ff>2.5</span>, linestyle<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;--&#34;</span>)
</span></span><span style=display:flex><span>plt<span style=color:#f92672>.</span>scatter([t, ], [np<span style=color:#f92672>.</span>cos(t), ], <span style=color:#ae81ff>50</span>, color<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;blue&#39;</span>)
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>plt<span style=color:#f92672>.</span>annotate(<span style=color:#e6db74>r</span><span style=color:#e6db74>&#39;$sin(\frac{2\pi}</span><span style=color:#e6db74>{3}</span><span style=color:#e6db74>)=\frac{\sqrt</span><span style=color:#e6db74>{3}</span><span style=color:#e6db74>}</span><span style=color:#e6db74>{2}</span><span style=color:#e6db74>$&#39;</span>,
</span></span><span style=display:flex><span>	xy<span style=color:#f92672>=</span>(t, np<span style=color:#f92672>.</span>sin(t)), xycoords<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;data&#39;</span>,
</span></span><span style=display:flex><span>	xytext<span style=color:#f92672>=</span>(<span style=color:#f92672>+</span><span style=color:#ae81ff>10</span>, <span style=color:#f92672>+</span><span style=color:#ae81ff>30</span>), textcoords<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;offset points&#39;</span>, fontsize<span style=color:#f92672>=</span><span style=color:#ae81ff>16</span>,
</span></span><span style=display:flex><span>	arrowprops<span style=color:#f92672>=</span>dict(arrowstyle<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;-&gt;&#34;</span>, connectionstyle<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;arc3,rad=.2&#34;</span>))
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>plt<span style=color:#f92672>.</span>plot([t, t],[<span style=color:#ae81ff>0</span>, np<span style=color:#f92672>.</span>sin(t)], color<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;red&#39;</span>, linewidth<span style=color:#f92672>=</span><span style=color:#ae81ff>2.5</span>, linestyle<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;--&#34;</span>)
</span></span><span style=display:flex><span>plt<span style=color:#f92672>.</span>scatter([t, ],[np<span style=color:#f92672>.</span>sin(t), ], <span style=color:#ae81ff>50</span>, color<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;red&#39;</span>)
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>plt<span style=color:#f92672>.</span>annotate(<span style=color:#e6db74>r</span><span style=color:#e6db74>&#39;$cos(\frac{2\pi}</span><span style=color:#e6db74>{3}</span><span style=color:#e6db74>)=-\frac</span><span style=color:#e6db74>{1}{2}</span><span style=color:#e6db74>$&#39;</span>,
</span></span><span style=display:flex><span>	xy<span style=color:#f92672>=</span>(t, np<span style=color:#f92672>.</span>cos(t)), xycoords<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;data&#39;</span>,
</span></span><span style=display:flex><span>	xytext<span style=color:#f92672>=</span>(<span style=color:#f92672>-</span><span style=color:#ae81ff>90</span>, <span style=color:#f92672>-</span><span style=color:#ae81ff>50</span>), textcoords<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;offset points&#39;</span>, fontsize<span style=color:#f92672>=</span><span style=color:#ae81ff>16</span>,
</span></span><span style=display:flex><span>arrowprops<span style=color:#f92672>=</span>dict(arrowstyle<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;-&gt;&#34;</span>, connectionstyle<span style=color:#f92672>=</span><span style=color:#e6db74>&#34;arc3,rad=.2&#34;</span>))
</span></span></code></pre></div><h3 id=坐标标签显示方案>坐标标签显示方案
<a class=anchor href=#%e5%9d%90%e6%a0%87%e6%a0%87%e7%ad%be%e6%98%be%e7%a4%ba%e6%96%b9%e6%a1%88>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=display:flex><span>    plt<span style=color:#f92672>.</span>setp(plt<span style=color:#f92672>.</span>gca()<span style=color:#f92672>.</span>get_xticklabels(), rotation<span style=color:#f92672>=</span><span style=color:#ae81ff>20</span>, horizontalalignment<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;right&#39;</span>)
</span></span><span style=display:flex><span>    <span style=color:#75715e># 貌似除了角度和right，没有了修改内容</span>
</span></span></code></pre></div><h3 id=来画一个动态图吧感觉没啥作用所以就小标题了>来画一个动态图吧（感觉没啥作用所以就小标题了）
<a class=anchor href=#%e6%9d%a5%e7%94%bb%e4%b8%80%e4%b8%aa%e5%8a%a8%e6%80%81%e5%9b%be%e5%90%a7%e6%84%9f%e8%a7%89%e6%b2%a1%e5%95%a5%e4%bd%9c%e7%94%a8%e6%89%80%e4%bb%a5%e5%b0%b1%e5%b0%8f%e6%a0%87%e9%a2%98%e4%ba%86>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=display:flex><span>    <span style=color:#f92672>import</span> matplotlib.pyplot <span style=color:#66d9ef>as</span> plt
</span></span><span style=display:flex><span>    <span style=color:#f92672>from</span> matplotlib.patches <span style=color:#f92672>import</span> Circle
</span></span><span style=display:flex><span>    <span style=color:#f92672>import</span> numpy <span style=color:#66d9ef>as</span> np
</span></span><span style=display:flex><span>    <span style=color:#f92672>import</span> math
</span></span><span style=display:flex><span>    
</span></span><span style=display:flex><span>    plt<span style=color:#f92672>.</span>close()  <span style=color:#75715e>#clf() # 清图  cla() # 清坐标轴 close() # 关窗口</span>
</span></span><span style=display:flex><span>    fig<span style=color:#f92672>=</span>plt<span style=color:#f92672>.</span>figure()
</span></span><span style=display:flex><span>    ax<span style=color:#f92672>=</span>fig<span style=color:#f92672>.</span>add_subplot(<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>1</span>)
</span></span><span style=display:flex><span>    ax<span style=color:#f92672>.</span>axis(<span style=color:#e6db74>&#34;equal&#34;</span>) <span style=color:#75715e>#设置图像显示的时候XY轴比例</span>
</span></span><span style=display:flex><span>    plt<span style=color:#f92672>.</span>grid(<span style=color:#66d9ef>True</span>) <span style=color:#75715e>#添加网格</span>
</span></span><span style=display:flex><span>    plt<span style=color:#f92672>.</span>ion()   <span style=color:#75715e>#interactive mode on打开交互模式 而不是plt.show()</span>
</span></span><span style=display:flex><span>    IniObsX<span style=color:#f92672>=</span><span style=color:#ae81ff>0000</span>
</span></span><span style=display:flex><span>    IniObsY<span style=color:#f92672>=</span><span style=color:#ae81ff>4000</span>
</span></span><span style=display:flex><span>    IniObsAngle<span style=color:#f92672>=</span><span style=color:#ae81ff>135</span>
</span></span><span style=display:flex><span>    IniObsSpeed<span style=color:#f92672>=</span><span style=color:#ae81ff>10</span><span style=color:#f92672>*</span>math<span style=color:#f92672>.</span>sqrt(<span style=color:#ae81ff>2</span>)   <span style=color:#75715e>#米/秒</span>
</span></span><span style=display:flex><span>    print(<span style=color:#e6db74>&#39;开始仿真&#39;</span>)
</span></span><span style=display:flex><span>    <span style=color:#66d9ef>try</span>:
</span></span><span style=display:flex><span>        <span style=color:#66d9ef>for</span> t <span style=color:#f92672>in</span> range(<span style=color:#ae81ff>180</span>):
</span></span><span style=display:flex><span>                <span style=color:#75715e>#障碍物船只轨迹             </span>
</span></span><span style=display:flex><span>            obsX<span style=color:#f92672>=</span>IniObsX<span style=color:#f92672>+</span>IniObsSpeed<span style=color:#f92672>*</span>math<span style=color:#f92672>.</span>sin(IniObsAngle<span style=color:#f92672>/</span><span style=color:#ae81ff>180</span><span style=color:#f92672>*</span>math<span style=color:#f92672>.</span>pi)<span style=color:#f92672>*</span>t
</span></span><span style=display:flex><span>            obsY<span style=color:#f92672>=</span>IniObsY<span style=color:#f92672>+</span>IniObsSpeed<span style=color:#f92672>*</span>math<span style=color:#f92672>.</span>cos(IniObsAngle<span style=color:#f92672>/</span><span style=color:#ae81ff>180</span><span style=color:#f92672>*</span>math<span style=color:#f92672>.</span>pi)<span style=color:#f92672>*</span>t
</span></span><span style=display:flex><span>            ax<span style=color:#f92672>.</span>scatter(obsX,obsY,c<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;b&#39;</span>,marker<span style=color:#f92672>=</span><span style=color:#e6db74>&#39;.&#39;</span>)  
</span></span><span style=display:flex><span>            <span style=color:#75715e>#散点图</span>
</span></span><span style=display:flex><span>            <span style=color:#75715e>#ax.lines.pop(1)  删除轨迹</span>
</span></span><span style=display:flex><span>            <span style=color:#75715e>#下面的图,两船的距离</span>
</span></span><span style=display:flex><span>            plt<span style=color:#f92672>.</span>pause(<span style=color:#ae81ff>0.1</span>)
</span></span><span style=display:flex><span>    <span style=color:#66d9ef>except</span> <span style=color:#a6e22e>Exception</span> <span style=color:#66d9ef>as</span> err:
</span></span><span style=display:flex><span>        print(err)
</span></span></code></pre></div><h2 id=pandas>pandas
<a class=anchor href=#pandas>#</a></h2><h3 id=dataframe>DataFrame
<a class=anchor href=#dataframe>#</a></h3><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=display:flex><span>    <span style=color:#f92672>import</span> pandas <span style=color:#66d9ef>as</span> pd
</span></span><span style=display:flex><span>    <span style=color:#f92672>import</span> numpy <span style=color:#66d9ef>as</span> np
</span></span><span style=display:flex><span>    a <span style=color:#f92672>=</span> {<span style=color:#e6db74>&#39;a&#39;</span>:[<span style=color:#e6db74>&#39;A&#39;</span>,<span style=color:#e6db74>&#39;B&#39;</span>,<span style=color:#e6db74>&#39;C&#39;</span>], <span style=color:#e6db74>&#39;b&#39;</span>:[<span style=color:#ae81ff>1</span>,<span style=color:#ae81ff>2</span>,<span style=color:#ae81ff>3</span>], <span style=color:#e6db74>&#39;c&#39;</span>:[<span style=color:#e6db74>&#39;lo&#39;</span>, <span style=color:#e6db74>&#39;hel&#39;</span>, <span style=color:#e6db74>&#39;hi&#39;</span>], <span style=color:#e6db74>&#39;d&#39;</span>:[<span style=color:#ae81ff>7</span>,<span style=color:#ae81ff>8</span>,<span style=color:#ae81ff>9</span>]}
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>    df <span style=color:#f92672>=</span> pd<span style=color:#f92672>.</span>DataFrame(a)
</span></span><span style=display:flex><span>    <span style=color:#75715e># 字典转换为dataFrame（每一个Key 和 Value构成一列，key为列标）</span>
</span></span><span style=display:flex><span>    df <span style=color:#f92672>=</span> df<span style=color:#f92672>.</span>set_index(<span style=color:#e6db74>&#39;a&#39;</span>)
</span></span><span style=display:flex><span>    <span style=color:#75715e># 将‘a‘列设置为行标</span>
</span></span><span style=display:flex><span>    sr <span style=color:#f92672>=</span> pd<span style=color:#f92672>.</span>Series(a)
</span></span><span style=display:flex><span>    sr2 <span style=color:#f92672>=</span> df[<span style=color:#e6db74>&#39;b&#39;</span>]
</span></span><span style=display:flex><span>
</span></span><span style=display:flex><span>    df[[<span style=color:#e6db74>&#39;b&#39;</span>,<span style=color:#e6db74>&#39;c&#39;</span>]]<span style=color:#f92672>.</span>to_records()[<span style=color:#ae81ff>1</span>][<span style=color:#e6db74>&#39;b&#39;</span>]
</span></span><span style=display:flex><span>    df[[<span style=color:#e6db74>&#39;b&#39;</span>,<span style=color:#e6db74>&#39;c&#39;</span>]]
</span></span></code></pre></div><h4 id=columns--index>columns index
<a class=anchor href=#columns--index>#</a></h4><pre><code>列，参数(行)
</code></pre><h4 id=取用方法>取用方法
<a class=anchor href=#%e5%8f%96%e7%94%a8%e6%96%b9%e6%b3%95>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=display:flex><span>    dfValue<span style=color:#f92672>.</span>loc[indexKey][colKey]
</span></span></code></pre></div><h4 id=一个将dataframe字符串化之后重新解析的程序>一个将<code>DataFrame</code>字符串化之后重新解析的程序😓
<a class=anchor href=#%e4%b8%80%e4%b8%aa%e5%b0%86dataframe%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%8c%96%e4%b9%8b%e5%90%8e%e9%87%8d%e6%96%b0%e8%a7%a3%e6%9e%90%e7%9a%84%e7%a8%8b%e5%ba%8f>#</a></h4><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-python data-lang=python><span style=display:flex><span>    <span style=color:#66d9ef>def</span> <span style=color:#a6e22e>parseSTR</span>(self, _str, indexKey, colKey, setIndexNum<span style=color:#f92672>=</span><span style=color:#ae81ff>0</span>, setColNum<span style=color:#f92672>=</span><span style=color:#ae81ff>0</span>):
</span></span><span style=display:flex><span>        <span style=color:#e6db74>&#34;&#34;&#34;
</span></span></span><span style=display:flex><span><span style=color:#e6db74>        通过setIndexNum来确定第几列数据为行标题， setColNum确定使用第几行数据作为列标题
</span></span></span><span style=display:flex><span><span style=color:#e6db74>        返回通过indexKey行标题 与 colKey列标题 确定的结果
</span></span></span><span style=display:flex><span><span style=color:#e6db74>        &#34;&#34;&#34;</span>
</span></span><span style=display:flex><span>        rows <span style=color:#f92672>=</span> _str<span style=color:#f92672>.</span>split(<span style=color:#e6db74>&#39;</span><span style=color:#ae81ff>\n</span><span style=color:#e6db74>&#39;</span>)
</span></span><span style=display:flex><span>        columns <span style=color:#f92672>=</span> rows[<span style=color:#ae81ff>0</span>]<span style=color:#f92672>.</span>split(<span style=color:#e6db74>&#39;,&#39;</span>)[<span style=color:#ae81ff>1</span>:]
</span></span><span style=display:flex><span>        tempRow <span style=color:#f92672>=</span> []
</span></span><span style=display:flex><span>        index <span style=color:#f92672>=</span> []
</span></span><span style=display:flex><span>        <span style=color:#66d9ef>for</span> row <span style=color:#f92672>in</span> rows[<span style=color:#ae81ff>1</span>:]:
</span></span><span style=display:flex><span>            <span style=color:#66d9ef>if</span> len(row):
</span></span><span style=display:flex><span>                index<span style=color:#f92672>.</span>append(row<span style=color:#f92672>.</span>split(<span style=color:#e6db74>&#39;,&#39;</span>)[setIndexNum])
</span></span><span style=display:flex><span>                tempRow<span style=color:#f92672>.</span>append(row<span style=color:#f92672>.</span>split(<span style=color:#e6db74>&#39;,&#39;</span>)[<span style=color:#ae81ff>1</span>:])
</span></span><span style=display:flex><span>        dfValue <span style=color:#f92672>=</span> pd<span style=color:#f92672>.</span>DataFrame(tempRow, index<span style=color:#f92672>=</span>index, columns<span style=color:#f92672>=</span>columns)
</span></span><span style=display:flex><span>        <span style=color:#66d9ef>try</span>:
</span></span><span style=display:flex><span>            <span style=color:#66d9ef>return</span> dfValue<span style=color:#f92672>.</span>loc[indexKey][colKey]
</span></span><span style=display:flex><span>        <span style=color:#66d9ef>except</span>:
</span></span><span style=display:flex><span>            print <span style=color:#e6db74>u</span><span style=color:#e6db74>&#39;【error:】信息不全&#39;</span>
</span></span><span style=display:flex><span>            <span style=color:#66d9ef>return</span> <span style=color:#66d9ef>None</span>
</span></span></code></pre></div><p>Emm,有点儿… 嗯… 嗯…</p><h2 id=numpy>numpy
<a class=anchor href=#numpy>#</a></h2><h3 id=random>random
<a class=anchor href=#random>#</a></h3><pre><code>random.seed(int类型) 
# 理解可以为设定开始随机的开始，也就是说每次设定之后再开始取值就会得到相同的随机数()
</code></pre><p>即
np.random.seed(1)<br>np.random.random(1)</p><pre><code>np.random.seed(1)   
np.random.random(1)
</code></pre><blockquote><p>array([ 0.417022])</p></blockquote><blockquote><p>array([ 0.417022])</p></blockquote><h4 id=标准差>标准差
<a class=anchor href=#%e6%a0%87%e5%87%86%e5%b7%ae>#</a></h4><pre><code>a = np.arange(10)
np.std(a)
a.std()
</code></pre><h5 id=样本标准差>样本标准差
<a class=anchor href=#%e6%a0%b7%e6%9c%ac%e6%a0%87%e5%87%86%e5%b7%ae>#</a></h5><pre><code>a.std(ddof = 1)
np.std(a, ddof = 1)
</code></pre><p>以上 a.std 只有当a为&lt;type &rsquo;numpy.ndarray&rsquo;> 即用numpy生成的矩阵，array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])才可有，如果是python的列表list 则只能用np.std 来算</p><h2 id=scikit-learn>scikit-learn
<a class=anchor href=#scikit-learn>#</a></h2><h2 id=opencv>OpenCV
<a class=anchor href=#opencv>#</a></h2><h3 id=insatll>Insatll
<a class=anchor href=#insatll>#</a></h3><p>caffe：</p><pre><code>sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
sudo apt-get install --no-install-recommends libboost-all-dev

sudo apt-get install libatlas-base-dev

sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
</code></pre><h2 id=pil>PIL
<a class=anchor href=#pil>#</a></h2><pre><code>his = im.histogram()
</code></pre><p>values = {}</p><p>for i in range(256):
values[i] = his[i]</p><p>for j,k in sorted(values.items(),key=lambda x:x[1],reverse = True)[:10]:
print j,k</p><h1 id=爬虫>爬虫
<a class=anchor href=#%e7%88%ac%e8%99%ab>#</a></h1><p>先<a href=https://edu.hellobi.com/course/156/reviews>链接</a> 为实例视频教程，貌似不错，还没看。</p><h2 id=问题>问题
<a class=anchor href=#%e9%97%ae%e9%a2%98>#</a></h2><p>虽然, 以前已经积累了一些东西, 知道</p><ul><li>headers</li><li>cookie
啥的, 但今天突然碰到了这个报错:</li></ul><blockquote><p>Caused by SSLError(SSLError(&ldquo;bad handshake: Error([(&lsquo;SSL routines&rsquo;, &rsquo;tls_process_server_certificate&rsquo;, &lsquo;certificate verify failed&rsquo;)])</p></blockquote><p>没见过, 之后碰到其余, 统一汇总在此.</p><h3 id=sslerror-https>SSLError HTTPS
<a class=anchor href=#sslerror-https>#</a></h3><p>有人指点到: 因用<code>https</code>的缘故, 其中报 <code>verify failed</code> 所以可以通过</p><div class=highlight><pre tabindex=0 style=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><code class=language-py data-lang=py><span style=display:flex><span>requests<span style=color:#f92672>.</span>get(url, verify<span style=color:#f92672>=</span><span style=color:#66d9ef>False</span>)
</span></span></code></pre></div><p>将<code>verify</code>关闭可通过.</p><h2 id=selenium>Selenium
<a class=anchor href=#selenium>#</a></h2><h4 id=从网页粘来的下方有作者以及来源链接格式就保留原有不改了>从网页粘来的，下方有作者以及来源链接，格式就保留原有不改了…
<a class=anchor href=#%e4%bb%8e%e7%bd%91%e9%a1%b5%e7%b2%98%e6%9d%a5%e7%9a%84%e4%b8%8b%e6%96%b9%e6%9c%89%e4%bd%9c%e8%80%85%e4%bb%a5%e5%8f%8a%e6%9d%a5%e6%ba%90%e9%93%be%e6%8e%a5%e6%a0%bc%e5%bc%8f%e5%b0%b1%e4%bf%9d%e7%95%99%e5%8e%9f%e6%9c%89%e4%b8%8d%e6%94%b9%e4%ba%86>#</a></h4><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.taobao.com/%27>https://www.taobao.com/'</a>)</p><h4 id=显示等待10s>显示等待10s
<a class=anchor href=#%e6%98%be%e7%a4%ba%e7%ad%89%e5%be%8510s>#</a></h4><p>wait = WebDriverWait(browser, 10)</p><h4 id=等待直到元素加载出>等待直到元素加载出
<a class=anchor href=#%e7%ad%89%e5%be%85%e7%9b%b4%e5%88%b0%e5%85%83%e7%b4%a0%e5%8a%a0%e8%bd%bd%e5%87%ba>#</a></h4><p>input = wait.until(EC.presence_of_element_located((By.ID, &lsquo;q&rsquo;)))</p><h4 id=等待直到元素可点击>等待直到元素可点击
<a class=anchor href=#%e7%ad%89%e5%be%85%e7%9b%b4%e5%88%b0%e5%85%83%e7%b4%a0%e5%8f%af%e7%82%b9%e5%87%bb>#</a></h4><p>button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, &lsquo;.btn-search&rsquo;)))
print(input, button)
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait</p><h4 id=创建一个浏览器对象>创建一个浏览器对象
<a class=anchor href=#%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1>#</a></h4><p>browser = webdriver.Chrome()
try:
# 开启一个浏览器并访问https://www.baidu.com
browser.get(&lsquo;<a href=https://www.baidu.com>https://www.baidu.com</a>&rsquo;)
# 在打开的网页响应中根据id查找元素 获取到查询框
input = browser.find_element_by_id(&lsquo;kw&rsquo;)
# 向查询框中输入Python
input.send_keys(&lsquo;Python&rsquo;)
# 模拟回车
input.send_keys(Keys.ENTER)
# 显示等待， 等待10秒
wait = WebDriverWait(browser, 10)
# 显式等待指定某个条件，然后设置最长等待时间。如果在这个时间还没有找到元素，那么便会抛出异常
wait.until(EC.presence_of_element_located((By.ID,&lsquo;content_left&rsquo;)))
# 输出当前的url
print(browser.current_url)
# 输出Cookies
print(browser.get_cookies())
# 输出页面响应内容
print(browser.page_source)
finally:
pass
# 关闭浏览器
browser.close()
2、Selenium声明浏览器对象from selenium import webdriver</p><p>browser = webdriver.Chrome()
browser = webdriver.Firefox()
browser = webdriver.Edge()
browser = webdriver.PhantomJS()
browser = webdriver.Safari()
3、查找元素3.1、查找单个元素from selenium import webdriver</p><h4 id=申明一个浏览器对象>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1>#</a></h4><p>browser = webdriver.Chrome()</p><h4 id=使用浏览器访问淘宝>使用浏览器访问淘宝
<a class=anchor href=#%e4%bd%bf%e7%94%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e8%ae%bf%e9%97%ae%e6%b7%98%e5%ae%9d>#</a></h4><p>browser.get(&lsquo;<a href=https://www.taobao.com>https://www.taobao.com</a>&rsquo;)</p><h4 id=在响应结果中通过id查找元素>在响应结果中通过id查找元素
<a class=anchor href=#%e5%9c%a8%e5%93%8d%e5%ba%94%e7%bb%93%e6%9e%9c%e4%b8%ad%e9%80%9a%e8%bf%87id%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0>#</a></h4><p>input_first = browser.find_element_by_id(&lsquo;q&rsquo;)</p><h4 id=在响应结果中通过css选择器查找元素>在响应结果中通过css选择器查找元素
<a class=anchor href=#%e5%9c%a8%e5%93%8d%e5%ba%94%e7%bb%93%e6%9e%9c%e4%b8%ad%e9%80%9a%e8%bf%87css%e9%80%89%e6%8b%a9%e5%99%a8%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0>#</a></h4><p>input_second = browser.find_element_by_css_selector(&rsquo;#q&rsquo;)</p><h4 id=在响应结果中通过xpath查找元素>在响应结果中通过xpath查找元素
<a class=anchor href=#%e5%9c%a8%e5%93%8d%e5%ba%94%e7%bb%93%e6%9e%9c%e4%b8%ad%e9%80%9a%e8%bf%87xpath%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0>#</a></h4><p>input_third = browser.find_element_by_xpath(&rsquo;//*[@id=&ldquo;q&rdquo;]&rsquo;)
print(input_first)
print(input_second)
print(input_third)
browser.close()
find_element_by_name 通过name查找find_element_by_xpath 通过xpath查找find_element_by_link_text 通过链接查找find_element_by_partial_link_text 通过部分链接查找find_element_by_tag_name 通过标签名称查找find_element_by_class_name 通过类名查找find_element_by_css_selector 通过css选择武器查找from selenium import webdriver
from selenium.webdriver.common.by import By</p><h4 id=申明一个浏览器对象-1>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-1>#</a></h4><p>browser = webdriver.Chrome()</p><h4 id=使用浏览器访问淘宝-1>使用浏览器访问淘宝
<a class=anchor href=#%e4%bd%bf%e7%94%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e8%ae%bf%e9%97%ae%e6%b7%98%e5%ae%9d-1>#</a></h4><p>browser.get(&lsquo;<a href=https://www.taobao.com>https://www.taobao.com</a>&rsquo;)</p><h4 id=第二种方式通过使用byxxx指定查找方式>第二种方式，通过使用By.xxx指定查找方式
<a class=anchor href=#%e7%ac%ac%e4%ba%8c%e7%a7%8d%e6%96%b9%e5%bc%8f%e9%80%9a%e8%bf%87%e4%bd%bf%e7%94%a8byxxx%e6%8c%87%e5%ae%9a%e6%9f%a5%e6%89%be%e6%96%b9%e5%bc%8f>#</a></h4><p>input = browser.find_element(By.ID,&lsquo;q&rsquo;)
print(input)
browser.close()
3.2、多个元素from selenium import webdriver
from selenium.webdriver.common.by import By</p><h4 id=申明一个浏览器对象-2>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-2>#</a></h4><p>browser = webdriver.Chrome()</p><h4 id=使用浏览器访问淘宝-2>使用浏览器访问淘宝
<a class=anchor href=#%e4%bd%bf%e7%94%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e8%ae%bf%e9%97%ae%e6%b7%98%e5%ae%9d-2>#</a></h4><p>browser.get(&lsquo;<a href=https://www.taobao.com>https://www.taobao.com</a>&rsquo;)</p><h4 id=根据选择查找多个元素>根据选择查找多个元素
<a class=anchor href=#%e6%a0%b9%e6%8d%ae%e9%80%89%e6%8b%a9%e6%9f%a5%e6%89%be%e5%a4%9a%e4%b8%aa%e5%85%83%e7%b4%a0>#</a></h4><p>input_first = browser.find_elements_by_css_selector(&rsquo;.service-bd li&rsquo;)
input_second = browser.find_elements(By.CSS_SELECTOR,&rsquo;.service-bd li&rsquo;)
print(input_first)
print(input_second)
browser.close()
find_elements_by_namefind_elements_by_xpathfind_elements_by_link_textfind_elements_by_partial_link_textfind_elements_by_tag_namefind_elements_by_class_namefind_elements_by_css_selector4、元素交互操作对获取的元素调用交互方法 import time
from selenium import webdriver
from selenium.webdriver.common.by import By</p><h4 id=申明一个浏览器对象-3>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-3>#</a></h4><p>browser = webdriver.Chrome()</p><h4 id=使用浏览器访问淘宝-3>使用浏览器访问淘宝
<a class=anchor href=#%e4%bd%bf%e7%94%a8%e6%b5%8f%e8%a7%88%e5%99%a8%e8%ae%bf%e9%97%ae%e6%b7%98%e5%ae%9d-3>#</a></h4><p>browser.get(&lsquo;<a href=https://www.taobao.com>https://www.taobao.com</a>&rsquo;)</p><h4 id=根据id查找元素>根据ID查找元素
<a class=anchor href=#%e6%a0%b9%e6%8d%aeid%e6%9f%a5%e6%89%be%e5%85%83%e7%b4%a0>#</a></h4><p>input_search = browser.find_element(By.ID,&lsquo;q&rsquo;)</p><h4 id=模拟输入psv到输入框>模拟输入PSV到输入框
<a class=anchor href=#%e6%a8%a1%e6%8b%9f%e8%be%93%e5%85%a5psv%e5%88%b0%e8%be%93%e5%85%a5%e6%a1%86>#</a></h4><p>input_search.send_keys(&lsquo;PSV&rsquo;)
time.sleep(2)</p><h4 id=清空输入>清空输入
<a class=anchor href=#%e6%b8%85%e7%a9%ba%e8%be%93%e5%85%a5>#</a></h4><p>input_search.clear()
input_search.send_keys(&lsquo;3DS&rsquo;)
button = browser.find_element(By.CLASS_NAME,&lsquo;btn-search&rsquo;)</p><h4 id=模拟点击>模拟点击
<a class=anchor href=#%e6%a8%a1%e6%8b%9f%e7%82%b9%e5%87%bb>#</a></h4><p>button.click()
更多的操作 http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.remote.webelement5、交互动作from selenium import webdriver
from selenium.webdriver import ActionChains</p><p>browser = webdriver.Chrome()
url = &lsquo;<a href="http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable%27">http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'</a>
browser.get(url)</p><h4 id=切换id为iframeresult的frame>切换id为iframeResult的frame
<a class=anchor href=#%e5%88%87%e6%8d%a2id%e4%b8%baiframeresult%e7%9a%84frame>#</a></h4><p>browser.switch_to.frame(&lsquo;iframeResult&rsquo;)
source = browser.find_element_by_css_selector(&rsquo;#draggable&rsquo;)
target = browser.find_element_by_css_selector(&rsquo;#droppable&rsquo;)
actions = ActionChains(browser)
actions.drag_and_drop(source, target)
actions.perform()
更多操作http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.action_chains6、执行JavaScriptfrom selenium import webdriver</p><h4 id=申明一个浏览器对象-4>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-4>#</a></h4><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.zhihu.com/explore%27>https://www.zhihu.com/explore'</a>)</p><h4 id=执行javascript脚本>执行JavaScript脚本
<a class=anchor href=#%e6%89%a7%e8%a1%8cjavascript%e8%84%9a%e6%9c%ac>#</a></h4><p>browser.execute_script(&lsquo;window.scrollTo(0, document.body.scrollHeight)&rsquo;)
browser.execute_script(&lsquo;alert(&ldquo;To Bottom&rdquo;)&rsquo;)
7、获取元素信息7.1、获取属性from selenium import webdriver
from selenium.webdriver.common.by import By</p><h4 id=申明一个浏览器对象-5>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-5>#</a></h4><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.zhihu.com/explore%27>https://www.zhihu.com/explore'</a>)
logo = browser.find_element(By.ID,&lsquo;zh-top-link-logo&rsquo;)</p><h4 id=获取属性>获取属性
<a class=anchor href=#%e8%8e%b7%e5%8f%96%e5%b1%9e%e6%80%a7>#</a></h4><p>print(logo.get_attribute(&lsquo;class&rsquo;))
print(logo)
browser.close()
7.2、获取文本值from selenium import webdriver
from selenium.webdriver.common.by import By</p><h4 id=申明一个浏览器对象-6>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-6>#</a></h4><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.zhihu.com/explore%27>https://www.zhihu.com/explore'</a>)
submit = browser.find_element(By.ID,&lsquo;zu-top-add-question&rsquo;)</p><h4 id=获取文本值>获取文本值
<a class=anchor href=#%e8%8e%b7%e5%8f%96%e6%96%87%e6%9c%ac%e5%80%bc>#</a></h4><p>print(submit.text)
print(submit)
browser.close()
7.3、获取ID、位置、标签名、大小from selenium import webdriver
from selenium.webdriver.common.by import By</p><h4 id=申明一个浏览器对象-7>申明一个浏览器对象
<a class=anchor href=#%e7%94%b3%e6%98%8e%e4%b8%80%e4%b8%aa%e6%b5%8f%e8%a7%88%e5%99%a8%e5%af%b9%e8%b1%a1-7>#</a></h4><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.zhihu.com/explore%27>https://www.zhihu.com/explore'</a>)
submit = browser.find_element(By.ID,&lsquo;zu-top-add-question&rsquo;)</p><h4 id=获取id---004584255991652042-1>获取id 0.04584255991652042-1
<a class=anchor href=#%e8%8e%b7%e5%8f%96id---004584255991652042-1>#</a></h4><p>print(submit.id)</p><h4 id=获取位置--y-7-x-675>获取位置 {&lsquo;y&rsquo;: 7, &lsquo;x&rsquo;: 675}
<a class=anchor href=#%e8%8e%b7%e5%8f%96%e4%bd%8d%e7%bd%ae--y-7-x-675>#</a></h4><p>print(submit.location)</p><h4 id=获取标签名称----button>获取标签名称 button
<a class=anchor href=#%e8%8e%b7%e5%8f%96%e6%a0%87%e7%ad%be%e5%90%8d%e7%a7%b0----button>#</a></h4><p>print(submit.tag_name)</p><h4 id=获取大小--width-66-height-32>获取大小 {&lsquo;width&rsquo;: 66, &lsquo;height&rsquo;: 32}
<a class=anchor href=#%e8%8e%b7%e5%8f%96%e5%a4%a7%e5%b0%8f--width-66-height-32>#</a></h4><p>print(submit.size)
browser.close()
8、Framefrom selenium import webdriver
from selenium.common.exceptions import NoSuchElementException</p><p>browser = webdriver.Chrome()
url = &lsquo;<a href="http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable%27">http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'</a>
browser.get(url)</p><h4 id=将操作的响应数据换成iframeresult>将操作的响应数据换成iframeResult
<a class=anchor href=#%e5%b0%86%e6%93%8d%e4%bd%9c%e7%9a%84%e5%93%8d%e5%ba%94%e6%95%b0%e6%8d%ae%e6%8d%a2%e6%88%90iframeresult>#</a></h4><p>browser.switch_to.frame(&lsquo;iframeResult&rsquo;)
source = browser.find_element_by_css_selector(&rsquo;#draggable&rsquo;)
print(source)
try:
logo = browser.find_element_by_class_name(&rsquo;logo&rsquo;)
except NoSuchElementException:
print(&lsquo;NO LOGO&rsquo;)</p><h4 id=切换成父元素>切换成父元素
<a class=anchor href=#%e5%88%87%e6%8d%a2%e6%88%90%e7%88%b6%e5%85%83%e7%b4%a0>#</a></h4><p>browser.switch_to.parent_frame()
logo = browser.find_element_by_class_name(&rsquo;logo&rsquo;)
print(logo)
print(logo.text)
9、等待9.1、隐式等待当使用了隐式等待执行测试的时候，如果 WebDriver没有在 DOM中找到元素，将继续等待，超出设定时间后则抛出找不到元素的异常, 换句话说，当查找元素或元素并没有立即出现的时候，隐式等待将等待一段时间再查找 DOM，默认的时间是0from selenium import webdriver</p><p>browser = webdriver.Chrome()</p><h4 id=等待10秒>等待10秒
<a class=anchor href=#%e7%ad%89%e5%be%8510%e7%a7%92>#</a></h4><p>browser.implicitly_wait(10)
browser.get(&lsquo;<a href=https://www.zhihu.com/explore%27>https://www.zhihu.com/explore'</a>)
input = browser.find_element_by_class_name(&lsquo;zu-top-add-question&rsquo;)
print(input)
9.2、显示等待显式等待指定某个条件，然后设置最长等待时间。如果在这个时间还没有找到元素，那么便会抛出异常了。 from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait</p><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.taobao.com/%27>https://www.taobao.com/'</a>)</p><h4 id=显示等待10s-1>显示等待10s
<a class=anchor href=#%e6%98%be%e7%a4%ba%e7%ad%89%e5%be%8510s-1>#</a></h4><p>wait = WebDriverWait(browser, 10)</p><h4 id=等待直到元素加载出-1>等待直到元素加载出
<a class=anchor href=#%e7%ad%89%e5%be%85%e7%9b%b4%e5%88%b0%e5%85%83%e7%b4%a0%e5%8a%a0%e8%bd%bd%e5%87%ba-1>#</a></h4><p>input = wait.until(EC.presence_of_element_located((By.ID, &lsquo;q&rsquo;)))</p><h4 id=等待直到元素可点击-1>等待直到元素可点击
<a class=anchor href=#%e7%ad%89%e5%be%85%e7%9b%b4%e5%88%b0%e5%85%83%e7%b4%a0%e5%8f%af%e7%82%b9%e5%87%bb-1>#</a></h4><p>button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, &lsquo;.btn-search&rsquo;)))
print(input, button)
title_is 标题是某内容title_contains 标题包含某内容presence_of_element_located 元素加载出，传入定位元组，如(By.ID, &lsquo;p&rsquo;)visibility_of_element_located 元素可见，传入定位元组visibility_of 可见，传入元素对象presence_of_all_elements_located 所有元素加载出text_to_be_present_in_element 某个元素文本包含某文字text_to_be_present_in_element_value 某个元素值包含某文字frame_to_be_available_and_switch_to_it frame加载并切换invisibility_of_element_located 元素不可见element_to_be_clickable 元素可点击staleness_of 判断一个元素是否仍在DOM，可判断页面是否已经刷新element_to_be_selected 元素可选择，传元素对象element_located_to_be_selected 元素可选择，传入定位元组element_selection_state_to_be 传入元素对象以及状态，相等返回True，否则返回Falseelement_located_selection_state_to_be 传入定位元组以及状态，相等返回True，否则返回Falsealert_is_present 是否出现Alert更多操作http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.support.expected_conditions10、前进后退import time
from selenium import webdriver</p><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.baidu.com/%27>https://www.baidu.com/'</a>)
browser.get(&lsquo;<a href=https://www.taobao.com/%27>https://www.taobao.com/'</a>)
browser.get(&lsquo;<a href=https://www.python.org/%27>https://www.python.org/'</a>)
browser.back()
time.sleep(1)
browser.forward()
browser.close()
11、Cookiesfrom selenium import webdriver</p><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.zhihu.com/explore%27>https://www.zhihu.com/explore'</a>)</p><h4 id=获得cookies>获得cookies
<a class=anchor href=#%e8%8e%b7%e5%be%97cookies>#</a></h4><p>print(browser.get_cookies())</p><h4 id=添加cookie>添加cookie
<a class=anchor href=#%e6%b7%bb%e5%8a%a0cookie>#</a></h4><p>browser.add_cookie({&rsquo;name&rsquo;: &rsquo;name&rsquo;, &lsquo;domain&rsquo;: &lsquo;<a href=https://www.zhihu.com>www.zhihu.com</a>&rsquo;, &lsquo;value&rsquo;: &lsquo;germey&rsquo;})
print(browser.get_cookies())</p><h4 id=删除所有cookies>删除所有cookies
<a class=anchor href=#%e5%88%a0%e9%99%a4%e6%89%80%e6%9c%89cookies>#</a></h4><p>browser.delete_all_cookies()
print(browser.get_cookies())
12、选项卡管理import time
from selenium import webdriver</p><p>browser = webdriver.Chrome()
browser.get(&lsquo;<a href=https://www.baidu.com>https://www.baidu.com</a>&rsquo;)</p><h4 id=打开一个选项卡>打开一个选项卡
<a class=anchor href=#%e6%89%93%e5%bc%80%e4%b8%80%e4%b8%aa%e9%80%89%e9%a1%b9%e5%8d%a1>#</a></h4><p>browser.execute_script(&lsquo;window.open()&rsquo;)
print(browser.window_handles)</p><h4 id=选择第二个选项卡>选择第二个选项卡
<a class=anchor href=#%e9%80%89%e6%8b%a9%e7%ac%ac%e4%ba%8c%e4%b8%aa%e9%80%89%e9%a1%b9%e5%8d%a1>#</a></h4><p>browser.switch_to_window(browser.window_handles[1])
browser.get(&lsquo;<a href=https://www.taobao.com>https://www.taobao.com</a>&rsquo;)
time.sleep(1)
browser.switch_to_window(browser.window_handles[0])
browser.get(&lsquo;<a href=https://python.org>https://python.org</a>&rsquo;)
13、异常处理from selenium import webdriver
from selenium.common.exceptions import TimeoutException, NoSuchElementException</p><p>browser = webdriver.Chrome()
try:
browser.get(&lsquo;<a href=https://www.baidu.com>https://www.baidu.com</a>&rsquo;)
except TimeoutException:
print(&lsquo;Time Out&rsquo;)
try:
browser.find_element_by_id(&lsquo;hello&rsquo;)
except NoSuchElementException:
print(&lsquo;No Element&rsquo;)
finally:
browser.close()
作者：蒋蜀黍 Python爱好者社区专栏作者 授权原创发布，请勿转载，谢谢。出处：Selenium 库学习笔记</p><h2 id=tensorflow>TensorFlow
<a class=anchor href=#tensorflow>#</a></h2><h4 id=variable>Variable
<a class=anchor href=#variable>#</a></h4><p>必须用到:
```init = tf.initialize_all_variables() #初始化全部变量</p><p>随后即可:
```sess.run(init)</p><h2 id=tensorflow-笔记>Tensorflow 笔记
<a class=anchor href=#tensorflow-%e7%ac%94%e8%ae%b0>#</a></h2><p>這是在對照官網學習時的前期入門筆記，其實和官網基本沒有區別，好吧，真的沒有區別。因爲官網真的寫的太好了。
至於我爲什麼要寫出來，是因爲我之前寫在了紙上，對於邏輯的把握很給力，所以在寫一邊。</p><p>不過TensorFlow 變動真的很大，版本更迭也很快，所以，下方只是理清邏輯，具體的東西還是去官網比較好。只不過我這兒網謎之很難等上去…</p><p>總而言之一句話，先搭好架子再選擇填充材料。就是它的核心邏輯了。而改進也是在架子基礎上去優化優化器。嗯…現在理解就是這樣。</p><h3 id=1-1>1
<a class=anchor href=#1-1>#</a></h3><h4 id=导入>导入
<a class=anchor href=#%e5%af%bc%e5%85%a5>#</a></h4><pre><code>import tensorflow as tf
</code></pre><p>步骤：①构建计算图 ②运行计算图</p><hr><h4 id=2>2
<a class=anchor href=#2>#</a></h4><h5 id=build-a-simple-computational-graph>Build a simple computational Graph
<a class=anchor href=#build-a-simple-computational-graph>#</a></h5><pre><code>node1 = tf.contant(3.0, dtype = tf.float32)
node2 = tf.contant(4.0) #also tf.float32 impicitly
print (node1, node2)
</code></pre><h6 id=输出为>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba>#</a></h6><pre><code>Tensor (&quot;Cast: 0&quot;, shape = (), dtype = float)
Tensor (&quot;Cast_1: 0&quot;, shape = (), dtype = float)
</code></pre><p>打印并不输出值3.0，4.0，而在评估时分别产生3.0和4.0节点。欲实际评估节点，We must run the computational graph within a session. A seesion encapsulation the control and state of the tensorflow runtime.</p><hr><h4 id=3>3
<a class=anchor href=#3>#</a></h4><h5 id=creates-a-session-object--然后调用-run-方法运行足够的computational-graph-to-envlute-node1-and-node2>Creates a session object , 然后调用<code>run</code>方法运行足够的computational graph to envlute node1 and node2
<a class=anchor href=#creates-a-session-object--%e7%84%b6%e5%90%8e%e8%b0%83%e7%94%a8-run-%e6%96%b9%e6%b3%95%e8%bf%90%e8%a1%8c%e8%b6%b3%e5%a4%9f%e7%9a%84computational-graph-to-envlute-node1-and-node2>#</a></h5><pre><code>sess = tf.Session()
print (sess.run([node1, node2]))
</code></pre><h6 id=输出为-1>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-1>#</a></h6><pre><code>[3.0,   4.0]        #可见预期值
</code></pre><hr><h4 id=4>4
<a class=anchor href=#4>#</a></h4><h5 id=we-can-build-more-complicated-computations-by-combining-tensor-nodes-with-operations>We can build more complicated computations by combining Tensor nodes with operations
<a class=anchor href=#we-can-build-more-complicated-computations-by-combining-tensor-nodes-with-operations>#</a></h5><pre><code>node3 = tf.add(node1, node2)
print (&quot;node3: &quot;, node3)
print (&quot;sess.run(node3):&quot;, sess.run(node3))
</code></pre><h6 id=输出为-2>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-2>#</a></h6><pre><code>node3:  Tensor(&quot;Add:0&quot;, shape = (1,dtype = float32))
sess.run(node3): 7.0
</code></pre><hr><h4 id=5>5
<a class=anchor href=#5>#</a></h4><h5 id=更进一步的a-graph-can-be-parameterized-to-accept-external-input--称为placeholders>更进一步的，A graph can be parameterized. To accept external input , 称为<code>placeholders</code>
<a class=anchor href=#%e6%9b%b4%e8%bf%9b%e4%b8%80%e6%ad%a5%e7%9a%84a-graph-can-be-parameterized-to-accept-external-input--%e7%a7%b0%e4%b8%baplaceholders>#</a></h5><pre><code>a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_note = a + b      #provide a shortcut for tf.add(a, b) and can with multiple input by using
print (sess.run(add_note, {a:3, b:4.5}))
print (sess.run(add_note, {a:[1, 3],  b:[2, 4]}))
</code></pre><h6 id=输出为-3>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-3>#</a></h6><pre><code>7.5
[3.  7.]
</code></pre><h5 id=51>5.1
<a class=anchor href=#51>#</a></h5><h5 id=more-complex-by-adding-anther-aperation-for-example>more complex by adding anther aperation. for example:
<a class=anchor href=#more-complex-by-adding-anther-aperation-for-example>#</a></h5><pre><code>add_and_triple = adder_note * 3
print (sess.run(add_and_triple, {a:3, b:4.5}))
</code></pre><h6 id=输出为-4>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-4>#</a></h6><pre><code>22.5
</code></pre><p>In <code>TensorBoard</code>(Tensorflow圖形化界面): 图片.jpg 是下面<code>a+b```` 然后连接到</code>adder_node<code> ,随后再连接到</code>y(add_and_triple)```</p><h5 id=52>5.2
<a class=anchor href=#52>#</a></h5><h5 id=that-a-model-that-can-take-arbitary-inputsto-mode-the-modeel-trainableneed-to-modify-the-graph-to-get-new-a-outputs-with-the-some-input--variables-allow-us>That a model that can take arbitary inputs:To mode the modeel trainable,need to modify the graph to get new a outputs with the some input : <code>Variables</code> allow us:
<a class=anchor href=#that-a-model-that-can-take-arbitary-inputsto-mode-the-modeel-trainableneed-to-modify-the-graph-to-get-new-a-outputs-with-the-some-input--variables-allow-us>#</a></h5><pre><code>w = tf.Variables([  .3], dtype = tf.float32)
b = tf.Variables([ -  .3], dtype = tf.float32)
x = tf.placeholder(tf.float32)
linear_model = w * x + b        #线性模型
</code></pre><hr><h4 id=6>6
<a class=anchor href=#6>#</a></h4><h5 id=使用tfconstant-调用初始化常数--用tfvaiables-變量不被初始化調用欲初始化所有變量必須calll-a-special-operation>使用<code>tf.constant</code> :调用、初始化常数 用<code>tf.Vaiables</code> :變量不被初始化，調用欲初始化所有變量，必須calll a special operation:
<a class=anchor href=#%e4%bd%bf%e7%94%a8tfconstant-%e8%b0%83%e7%94%a8%e5%88%9d%e5%a7%8b%e5%8c%96%e5%b8%b8%e6%95%b0--%e7%94%a8tfvaiables-%e8%ae%8a%e9%87%8f%e4%b8%8d%e8%a2%ab%e5%88%9d%e5%a7%8b%e5%8c%96%e8%aa%bf%e7%94%a8%e6%ac%b2%e5%88%9d%e5%a7%8b%e5%8c%96%e6%89%80%e6%9c%89%e8%ae%8a%e9%87%8f%e5%bf%85%e9%a0%88calll-a-special-operation>#</a></h5><pre><code>init = tf.global_variables_initializer()
sess.run(init)
</code></pre><hr><h4 id=7>7
<a class=anchor href=#7>#</a></h4><h5 id=x-is-a-placeholder-we-can-evaluate-lnear_model-for-several-values-of-x-simultaneausly-as-follow>x is a placeholder, we can evaluate <code>lnear_model</code> for several values of x simultaneausly as follow:
<a class=anchor href=#x-is-a-placeholder-we-can-evaluate-lnear_model-for-several-values-of-x-simultaneausly-as-follow>#</a></h5><pre><code>print (sess.run(linear_model, {x:[1,2,3,4]}))
</code></pre><h6 id=輸出爲>輸出爲：
<a class=anchor href=#%e8%bc%b8%e5%87%ba%e7%88%b2>#</a></h6><pre><code>[0.        0.30000001   0.60000002  0.90000004]
</code></pre><hr><h4 id=8>8
<a class=anchor href=#8>#</a></h4><h5 id=有以上結果並不知好壞因此編寫損失函數>有以上結果並不知好壞，因此編寫損失函數：
<a class=anchor href=#%e6%9c%89%e4%bb%a5%e4%b8%8a%e7%b5%90%e6%9e%9c%e4%b8%a6%e4%b8%8d%e7%9f%a5%e5%a5%bd%e5%a3%9e%e5%9b%a0%e6%ad%a4%e7%b7%a8%e5%af%ab%e6%90%8d%e5%a4%b1%e5%87%bd%e6%95%b8>#</a></h5><pre><code>y = tf.placeholder(tf.float32)
squared_deltas = tf.square(linear_model - y)        #平方（下方差和）
loss = tf.reduce_sum(squred_deltas)     #差和（上方平方）
print (sess.run)loss, {x:[1, 2, 3, 4], y:[0, -1, -2, -3]})
</code></pre><h6 id=輸出爲-1>輸出爲：
<a class=anchor href=#%e8%bc%b8%e5%87%ba%e7%88%b2-1>#</a></h6><pre><code>23.66       #損失值：差平方和
</code></pre><h5 id=81>8.1
<a class=anchor href=#81>#</a></h5><h5 id=we-could-improve-this-manually-wb-to-perfact-values-of--1-and-1-a-variable-is-initializef-to-the-value-provided-to-tfvariable-but-can-be-charged-using-operation-like-tfassign>We could improve this manually W,b to perfact values of -1 and 1. A variable is initializef to the value provided to <code>tf.Variable</code> but can be charged using operation like <code>tf.assign</code>
<a class=anchor href=#we-could-improve-this-manually-wb-to-perfact-values-of--1-and-1-a-variable-is-initializef-to-the-value-provided-to-tfvariable-but-can-be-charged-using-operation-like-tfassign>#</a></h5><h5 id=w---1-and-b--1-are-optimal-parameters最優參數>W = -1 and b = 1 are optimal parameters:(最優參數)
<a class=anchor href=#w---1-and-b--1-are-optimal-parameters%e6%9c%80%e5%84%aa%e5%8f%83%e6%95%b8>#</a></h5><pre><code>fixW = tf.assign(W, [-1.  ])
fixb = tf.assign(b,[1.  ])
sess.run(fixW, fixb)
print(sess.run(loss, {x:[1, 2, 3, 4],  y:[0, -1, -2, -3]}))
</code></pre><h6 id=輸出爲-2>輸出爲：
<a class=anchor href=#%e8%bc%b8%e5%87%ba%e7%88%b2-2>#</a></h6><pre><code>0, 0  # The final print shows the loss now is zero !
</code></pre><hr><h4 id=9>9
<a class=anchor href=#9>#</a></h4><h5 id=模型保存与加载>模型保存与加载：
<a class=anchor href=#%e6%a8%a1%e5%9e%8b%e4%bf%9d%e5%ad%98%e4%b8%8e%e5%8a%a0%e8%bd%bd>#</a></h5><h6 id=保存>保存：
<a class=anchor href=#%e4%bf%9d%e5%ad%98>#</a></h6><pre><code>saver = tf.train.Saver()    # 生成saver
with tf.Session() as sess:
sess.run(tf.global_variables_initializer()) # 先对模型初始化

# 然后将数据丢入模型进行训练blablabla

# 训练完以后，使用saver.save 来保存
saver.save(sess, &quot;save_path/file_name&quot;) #file_name如果不存在的话，会自动创建
</code></pre><h6 id=加载>加载：
<a class=anchor href=#%e5%8a%a0%e8%bd%bd>#</a></h6><pre><code>saver = tf.train.Saver()
with tf.Session() as sess:  #参数可以进行初始化，也可不进行初始化。即使初始化了，初始化的值也会被restore的值给覆盖
sess.run(tf.global_variables_initializer())
saver.restore(sess, &quot;save_path/file_name&quot;)  #会将已经保存的变量值resotre到 变量中。
</code></pre><hr><h4 id=10>10
<a class=anchor href=#10>#</a></h4><h5 id=图形化操作>图形化操作：
<a class=anchor href=#%e5%9b%be%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c>#</a></h5><pre><code>&gt;http://blog.csdn.net/u014595019/article/details/53912710
</code></pre><p>这篇写的还不错，等之后用过之后再写。</p><hr><hr><h4 id=variable-1>Variable
<a class=anchor href=#variable-1>#</a></h4><p>必须用到:
```init = tf.initialize_all_variables() #初始化全部变量</p><p>随后即可:
```sess.run(init)</p><h2 id=tensorflow-笔记-1>Tensorflow 笔记
<a class=anchor href=#tensorflow-%e7%ac%94%e8%ae%b0-1>#</a></h2><p>這是在對照官網學習時的前期入門筆記，其實和官網基本沒有區別，好吧，真的沒有區別。因爲官網真的寫的太好了。
至於我爲什麼要寫出來，是因爲我之前寫在了紙上，對於邏輯的把握很給力，所以在寫一邊。</p><p>不過TensorFlow 變動真的很大，版本更迭也很快，所以，下方只是理清邏輯，具體的東西還是去官網比較好。只不過我這兒網謎之很難等上去…</p><p>總而言之一句話，先搭好架子再選擇填充材料。就是它的核心邏輯了。而改進也是在架子基礎上去優化優化器。嗯…現在理解就是這樣。</p><h3 id=1-2>1
<a class=anchor href=#1-2>#</a></h3><h4 id=导入-1>导入
<a class=anchor href=#%e5%af%bc%e5%85%a5-1>#</a></h4><pre><code>import tensorflow as tf
</code></pre><p>步骤：①构建计算图 ②运行计算图</p><hr><h4 id=2-1>2
<a class=anchor href=#2-1>#</a></h4><h5 id=build-a-simple-computational-graph-1>Build a simple computational Graph
<a class=anchor href=#build-a-simple-computational-graph-1>#</a></h5><pre><code>node1 = tf.contant(3.0, dtype = tf.float32)
node2 = tf.contant(4.0)	#also tf.float32 impicitly
print (node1, node2)
</code></pre><h6 id=输出为-5>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-5>#</a></h6><pre><code>Tensor (&quot;Cast: 0&quot;, shape = (), dtype = float)
Tensor (&quot;Cast_1: 0&quot;, shape = (), dtype = float)
</code></pre><p>打印并不输出值3.0，4.0，而在评估时分别产生3.0和4.0节点。欲实际评估节点，We must run the computational graph within a session. A seesion encapsulation the control and state of the tensorflow runtime.</p><hr><h4 id=3-1>3
<a class=anchor href=#3-1>#</a></h4><h5 id=creates-a-session-object--然后调用-run-方法运行足够的computational-graph-to-envlute-node1-and-node2-1>Creates a session object , 然后调用<code>run</code>方法运行足够的computational graph to envlute node1 and node2
<a class=anchor href=#creates-a-session-object--%e7%84%b6%e5%90%8e%e8%b0%83%e7%94%a8-run-%e6%96%b9%e6%b3%95%e8%bf%90%e8%a1%8c%e8%b6%b3%e5%a4%9f%e7%9a%84computational-graph-to-envlute-node1-and-node2-1>#</a></h5><pre><code>sess = tf.Session()
print (sess.run([node1, node2]))
</code></pre><h6 id=输出为-6>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-6>#</a></h6><pre><code>[3.0,   4.0]		#可见预期值
</code></pre><hr><h4 id=4-1>4
<a class=anchor href=#4-1>#</a></h4><h5 id=we-can-build-more-complicated-computations-by-combining-tensor-nodes-with-operations-1>We can build more complicated computations by combining Tensor nodes with operations
<a class=anchor href=#we-can-build-more-complicated-computations-by-combining-tensor-nodes-with-operations-1>#</a></h5><pre><code>node3 = tf.add(node1, node2)
print (&quot;node3: &quot;, node3)
print (&quot;sess.run(node3):&quot;, sess.run(node3))
</code></pre><h6 id=输出为-7>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-7>#</a></h6><pre><code>node3:  Tensor(&quot;Add:0&quot;, shape = (1,dtype = float32))
sess.run(node3): 7.0
</code></pre><hr><h4 id=5-1>5
<a class=anchor href=#5-1>#</a></h4><h5 id=更进一步的a-graph-can-be-parameterized-to-accept-external-input--称为placeholders-1>更进一步的，A graph can be parameterized. To accept external input , 称为<code>placeholders</code>
<a class=anchor href=#%e6%9b%b4%e8%bf%9b%e4%b8%80%e6%ad%a5%e7%9a%84a-graph-can-be-parameterized-to-accept-external-input--%e7%a7%b0%e4%b8%baplaceholders-1>#</a></h5><pre><code>a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
adder_note = a + b		#provide a shortcut for tf.add(a, b) and can with multiple input by using
print (sess.run(add_note, {a:3, b:4.5}))
print (sess.run(add_note, {a:[1, 3],  b:[2, 4]}))
</code></pre><h6 id=输出为-8>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-8>#</a></h6><pre><code>7.5
[3.  7.]
</code></pre><h5 id=51-1>5.1
<a class=anchor href=#51-1>#</a></h5><h5 id=more-complex-by-adding-anther-aperation-for-example-1>more complex by adding anther aperation. for example:
<a class=anchor href=#more-complex-by-adding-anther-aperation-for-example-1>#</a></h5><pre><code>add_and_triple = adder_note * 3
print (sess.run(add_and_triple, {a:3, b:4.5}))
</code></pre><h6 id=输出为-9>输出为：
<a class=anchor href=#%e8%be%93%e5%87%ba%e4%b8%ba-9>#</a></h6><pre><code>22.5
</code></pre><p>In <code>TensorBoard</code>(Tensorflow圖形化界面): 图片.jpg 是下面<code>a+b```` 然后连接到</code>adder_node<code> ,随后再连接到</code>y(add_and_triple)```</p><h5 id=52-1>5.2
<a class=anchor href=#52-1>#</a></h5><h5 id=that-a-model-that-can-take-arbitary-inputsto-mode-the-modeel-trainableneed-to-modify-the-graph-to-get-new-a-outputs-with-the-some-input--variables-allow-us-1>That a model that can take arbitary inputs:To mode the modeel trainable,need to modify the graph to get new a outputs with the some input : <code>Variables</code> allow us:
<a class=anchor href=#that-a-model-that-can-take-arbitary-inputsto-mode-the-modeel-trainableneed-to-modify-the-graph-to-get-new-a-outputs-with-the-some-input--variables-allow-us-1>#</a></h5><pre><code>w = tf.Variables([  .3], dtype = tf.float32)
b = tf.Variables([ -  .3], dtype = tf.float32)
x = tf.placeholder(tf.float32)
linear_model = w * x + b		#线性模型
</code></pre><hr><h4 id=6-1>6
<a class=anchor href=#6-1>#</a></h4><h5 id=使用tfconstant-调用初始化常数--用tfvaiables-變量不被初始化調用欲初始化所有變量必須calll-a-special-operation-1>使用<code>tf.constant</code> :调用、初始化常数 用<code>tf.Vaiables</code> :變量不被初始化，調用欲初始化所有變量，必須calll a special operation:
<a class=anchor href=#%e4%bd%bf%e7%94%a8tfconstant-%e8%b0%83%e7%94%a8%e5%88%9d%e5%a7%8b%e5%8c%96%e5%b8%b8%e6%95%b0--%e7%94%a8tfvaiables-%e8%ae%8a%e9%87%8f%e4%b8%8d%e8%a2%ab%e5%88%9d%e5%a7%8b%e5%8c%96%e8%aa%bf%e7%94%a8%e6%ac%b2%e5%88%9d%e5%a7%8b%e5%8c%96%e6%89%80%e6%9c%89%e8%ae%8a%e9%87%8f%e5%bf%85%e9%a0%88calll-a-special-operation-1>#</a></h5><pre><code>init = tf.global_variables_initializer()
sess.run(init)
</code></pre><hr><h4 id=7-1>7
<a class=anchor href=#7-1>#</a></h4><h5 id=x-is-a-placeholder-we-can-evaluate-lnear_model-for-several-values-of-x-simultaneausly-as-follow-1>x is a placeholder, we can evaluate <code>lnear_model</code> for several values of x simultaneausly as follow:
<a class=anchor href=#x-is-a-placeholder-we-can-evaluate-lnear_model-for-several-values-of-x-simultaneausly-as-follow-1>#</a></h5><pre><code>print (sess.run(linear_model, {x:[1,2,3,4]}))
</code></pre><h6 id=輸出爲-3>輸出爲：
<a class=anchor href=#%e8%bc%b8%e5%87%ba%e7%88%b2-3>#</a></h6><pre><code>[0.        0.30000001   0.60000002  0.90000004]
</code></pre><hr><h4 id=8-1>8
<a class=anchor href=#8-1>#</a></h4><h5 id=有以上結果並不知好壞因此編寫損失函數-1>有以上結果並不知好壞，因此編寫損失函數：
<a class=anchor href=#%e6%9c%89%e4%bb%a5%e4%b8%8a%e7%b5%90%e6%9e%9c%e4%b8%a6%e4%b8%8d%e7%9f%a5%e5%a5%bd%e5%a3%9e%e5%9b%a0%e6%ad%a4%e7%b7%a8%e5%af%ab%e6%90%8d%e5%a4%b1%e5%87%bd%e6%95%b8-1>#</a></h5><pre><code>y = tf.placeholder(tf.float32)
squared_deltas = tf.square(linear_model - y)		#平方（下方差和）
loss = tf.reduce_sum(squred_deltas)		#差和（上方平方）
print (sess.run)loss, {x:[1, 2, 3, 4], y:[0, -1, -2, -3]})
</code></pre><h6 id=輸出爲-4>輸出爲：
<a class=anchor href=#%e8%bc%b8%e5%87%ba%e7%88%b2-4>#</a></h6><pre><code>23.66		#損失值：差平方和
</code></pre><h5 id=81-1>8.1
<a class=anchor href=#81-1>#</a></h5><h5 id=we-could-improve-this-manually-wb-to-perfact-values-of--1-and-1-a-variable-is-initializef-to-the-value-provided-to-tfvariable-but-can-be-charged-using-operation-like-tfassign-1>We could improve this manually W,b to perfact values of -1 and 1. A variable is initializef to the value provided to <code>tf.Variable</code> but can be charged using operation like <code>tf.assign</code>
<a class=anchor href=#we-could-improve-this-manually-wb-to-perfact-values-of--1-and-1-a-variable-is-initializef-to-the-value-provided-to-tfvariable-but-can-be-charged-using-operation-like-tfassign-1>#</a></h5><h5 id=w---1-and-b--1-are-optimal-parameters最優參數-1>W = -1 and b = 1 are optimal parameters:(最優參數)
<a class=anchor href=#w---1-and-b--1-are-optimal-parameters%e6%9c%80%e5%84%aa%e5%8f%83%e6%95%b8-1>#</a></h5><pre><code>fixW = tf.assign(W, [-1.  ])
fixb = tf.assign(b,[1.  ])
sess.run(fixW, fixb)
print(sess.run(loss, {x:[1, 2, 3, 4],  y:[0, -1, -2, -3]}))
</code></pre><h6 id=輸出爲-5>輸出爲：
<a class=anchor href=#%e8%bc%b8%e5%87%ba%e7%88%b2-5>#</a></h6><pre><code>0, 0  # The final print shows the loss now is zero !
</code></pre><hr><h4 id=9-1>9
<a class=anchor href=#9-1>#</a></h4><h5 id=模型保存与加载-1>模型保存与加载：
<a class=anchor href=#%e6%a8%a1%e5%9e%8b%e4%bf%9d%e5%ad%98%e4%b8%8e%e5%8a%a0%e8%bd%bd-1>#</a></h5><h6 id=保存-1>保存：
<a class=anchor href=#%e4%bf%9d%e5%ad%98-1>#</a></h6><pre><code>saver = tf.train.Saver()	# 生成saver
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())	# 先对模型初始化

# 然后将数据丢入模型进行训练blablabla

# 训练完以后，使用saver.save 来保存
saver.save(sess, &quot;save_path/file_name&quot;)	#file_name如果不存在的话，会自动创建
</code></pre><h6 id=加载-1>加载：
<a class=anchor href=#%e5%8a%a0%e8%bd%bd-1>#</a></h6><pre><code>saver = tf.train.Saver()
with tf.Session() as sess:	#参数可以进行初始化，也可不进行初始化。即使初始化了，初始化的值也会被restore的值给覆盖
sess.run(tf.global_variables_initializer())
saver.restore(sess, &quot;save_path/file_name&quot;)	#会将已经保存的变量值resotre到 变量中。
</code></pre><hr><h4 id=10-1>10
<a class=anchor href=#10-1>#</a></h4><h5 id=图形化操作-1>图形化操作：
<a class=anchor href=#%e5%9b%be%e5%bd%a2%e5%8c%96%e6%93%8d%e4%bd%9c-1>#</a></h5><pre><code>&lt;http://blog.csdn.net/u014595019/article/details/53912710&gt;
</code></pre><p>这篇写的还不错，等之后用过之后再写。</p></article><footer class=book-footer><div class="flex flex-wrap justify-between"></div><script>(function(){function e(e){const t=window.getSelection(),n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)}document.querySelectorAll("pre code").forEach(t=>{t.addEventListener("click",function(){if(window.getSelection().toString())return;e(t.parentElement),navigator.clipboard&&navigator.clipboard.writeText(t.parentElement.textContent)})})})()</script></footer><div class=book-comments></div><label for=menu-control class="hidden book-menu-overlay"></label></div><aside class=book-toc><div class=book-toc-content><nav id=TableOfContents><ul><li><ul><li><a href=#plotly>Plotly</a></li></ul></li><li><a href=#matplotlib>matplotlib</a><ul><li><a href=#参数等太多链接最可靠>参数等太多，链接最可靠</a></li><li><a href=#绘图>绘图</a></li><li><a href=#绘制图表>绘制图表</a></li><li><a href=#一表多图>一表多图</a></li><li><a href=#标注点>标注点</a></li><li><a href=#坐标标签显示方案>坐标标签显示方案</a></li><li><a href=#来画一个动态图吧感觉没啥作用所以就小标题了>来画一个动态图吧（感觉没啥作用所以就小标题了）</a></li></ul></li><li><a href=#pandas>pandas</a><ul><li><a href=#dataframe>DataFrame</a></li></ul></li><li><a href=#numpy>numpy</a><ul><li><a href=#random>random</a></li></ul></li><li><a href=#scikit-learn>scikit-learn</a></li><li><a href=#opencv>OpenCV</a><ul><li><a href=#insatll>Insatll</a></li></ul></li><li><a href=#pil>PIL</a></li></ul><ul><li><a href=#问题>问题</a><ul><li><a href=#sslerror-https>SSLError HTTPS</a></li></ul></li><li><a href=#selenium>Selenium</a><ul><li></li></ul></li><li><a href=#tensorflow>TensorFlow</a><ul><li></li></ul></li><li><a href=#tensorflow-笔记>Tensorflow 笔记</a><ul><li><a href=#1-1>1</a></li></ul></li><li><a href=#tensorflow-笔记-1>Tensorflow 笔记</a><ul><li><a href=#1-2>1</a></li></ul></li></ul></nav></div></aside></main></body></html>